#![allow(dead_code)]
use once_cell::sync::Lazy;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConstStore {
    pub cfg_interval: i64,
    pub cfg_time: i64,
    pub syn_zhcfg: SynZhCfg,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SynZhCfg {
    pub syn_zh_interval: i64,
    pub syn_zh_time: i64,
    pub syn_zh_cookie_interval: i64,
    pub syn_zh_cookie_time: i64,
}

static GLOBAL_CONST_STORE: Lazy<RwLock<ConstStore>> = Lazy::new(|| {
    RwLock::new(ConstStore::default())
});

// 简化获取全局实例的方法
pub fn global_store() -> &'static RwLock<ConstStore> {
    &GLOBAL_CONST_STORE
}

impl Default for ConstStore {
    fn default() -> Self {
        Self {
            cfg_interval: 3600,
            cfg_time: 0,
            syn_zhcfg: SynZhCfg::default(),
        }
    }
}

impl Default for SynZhCfg {
    fn default() -> Self {
        Self {
            syn_zh_interval: 60,
            syn_zh_time: 0,
            syn_zh_cookie_interval: 120,
            syn_zh_cookie_time: 0,
        }
    }
}